package cn.tedu.car.backend.xunfei.controller;


import cn.tedu.car.backend.base.response.JsonResult;
import cn.tedu.car.backend.base.response.StatusCode;
import cn.tedu.car.backend.xunfei.pojo.dto.XunFeiDTO;
import cn.tedu.car.backend.xunfei.service.XunFeiMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LLY
 */
@Slf4j
@RestController
@Api(tags = "讯飞AI接口")
@RequestMapping("/ai")
public class XunFeiMessageController {
    public static final String TOPIC = "车";
    @Autowired
    private XunFeiMessageService xunFeiMessageService;

    @GetMapping("/test")
    @ApiOperation(value = "讯飞接口")
    public JsonResult test(Long userId, String text) {
        log.debug("讯飞星火接口，当前用户：{},发送消息：{}",userId,text);
        if (text.isEmpty()||userId==null){
            return new JsonResult(StatusCode.NOT_LOGIN, "未登录或text不能为空");
        }
        if(!text.contains(TOPIC)){
            return new JsonResult(StatusCode.VALIDATE_ERROR, "您好，请说车相关话题");
        }
        XunFeiDTO xfDTO = new XunFeiDTO();
        xfDTO.setText(text);
        xfDTO.setUserId(userId);
        return xunFeiMessageService.pushMessageToXunFeiServer(xfDTO);
    }
}
